home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / bluebook.zip / GRAPHICS.ASM < prev    next >
Assembly Source File  |  1986-05-08  |  24KB  |  894 lines

  1.                                       COMMENT ~
  2. GRAPHICS.ASM -- Graphic Plotting Procedures
  3.  
  4.    From `BLUEBOOK of ASSEMBLY ROUTINES for the IBM PC & XT'
  5.          by Christopher L. Morgan
  6.          Copyright (C) 1984 by The Waite Group, Inc.
  7.  
  8.    Contents:
  9.    ---------
  10.    CLS        --  Clear the screen
  11.    GET_COLOR    --  Get the color of a point on the med res color screen
  12.    GMSG_OUT    --  Plot a string
  13.    PAINT    --  Fill an area with specified color
  14.    RCHAR    --  Plot a raster character
  15.    SCHAR    --  Plot a stroke character
  16.    SET_BOX    --  Fill a rectangular box with specified color
  17.    SET_LIN    --  Draw a line
  18.    SET_PT    --  Plot a point
  19.    XOR_BOX    --  Fill a rectangular box using XOR
  20.    XOR_PT    --  Plot a point using XOR
  21.  
  22.    >>>>>  See GRAPHICS.DOC for complete descriptions of these routines. <<<<<
  23.  ------------------------------------------------------------------------------
  24.  These variables need to be defined in the source code calling the GRAPHICS
  25.    routines. See GRAPHICS.DOC.                                                ~
  26. EXTRN    CBYTES:BYTE,    COLOR:WORD,    DELDE:WORD,    DELDX:WORD
  27. EXTRN    DELDY:WORD,    DELP:WORD,    DELS:WORD,    DELSE:WORD
  28. EXTRN    DELSX:WORD,    DELSY:WORD,    FONT:BYTE,    PAINT_STAK:WORD
  29. EXTRN    X0:WORD,    X1:WORD,    X2:WORD,    XMAGN:BYTE
  30. EXTRN    XMSG:WORD,    Y0:WORD,    Y1:WORD,    Y2:WORD
  31. EXTRN    YMAGN:BYTE,    YMSG:WORD
  32. ;______________________________________________________________________________
  33. ;These tables would be better included in the source code calling the 
  34. ;  GRAPHICS routines, and then commented out here.  See GRAPHICS.DOC
  35. ;        
  36. DATAS    SEGMENT    PUBLIC
  37.     CTABLE    DW    0003FH,0403FH,0803FH,0C03FH
  38.         DW    000CFH,010CFH,020CFH,030CFH
  39.         DW    000F3H,004F3H,008F3H,00CF3H
  40.         DW    000FCH,001FCH,002FCH,003FCH
  41.  
  42.     PTABLE    DW    32 DUP(?)        ;A dummy (See GRAPHICS.DOC) 
  43.  
  44.     XTABLE    DW    0FFC0H,0FFF0H,0FFFCH,0FFFFH
  45.         DW    03FC0H,03FF0H,03FFCH,03FFFH
  46.         DW    00FC0H,00FF0H,00FFCH,00FFFH
  47.         DW    003C0H,003F0H,003FCH,003FFH
  48. DATAS    ENDS 
  49. ;______________________________________________________________________________
  50. ;        
  51. CODES    SEGMENT
  52.     PUBLIC CLS,SET_PT,XOR_PT,GET_COLOR,SET_BOX,XOR_BOX
  53.     PUBLIC SET_LIN,SCHAR,RCHAR,GMSG_OUT,PAINT
  54. ASSUME CS:CODES,DS:DATAS
  55. ;____________________________I/O ROUTINES______________________________________
  56. ;Routine to clear the graphics screen
  57. ;
  58. CLS    PROC    FAR
  59.     PUSH    CX                ;Save registers
  60.     PUSH    AX
  61. ;
  62. ;Set up the registers
  63.     MOV    CX,2000H            ;Word count of whole screen
  64.     MOV    AX,0                ;Zero pattern for the screen
  65.     MOV    DI,AX                ;Set starting address
  66.     CLD                    ;Go in forward direction
  67. ;
  68. ;Clear the screen with a single string operation
  69.     REP    STOSW                ;This clears the screen
  70. ;    
  71.     POP    AX                ;Restore registers
  72.     POP    CX
  73.     RET
  74. CLS    ENDP
  75. ;------------------------------------------------------------------------------
  76. ;Routine to plot a point on medium resolution color screen
  77. ;
  78. SET_PT    PROC    FAR
  79.     PUSH    BX                ;Save registers
  80.     PUSH    SI
  81.     PUSH    AX 
  82. ;
  83. ;Multiply Y-coord by bytes/row & adjust for even/odd lines
  84.     MOV    AX,DI                ;Get Y-coordinate into part
  85.     MOV    AH,AL                ; and  into high part
  86.     AND    AX,01FEH            ;Mask off unwanted parts
  87.     SAL    AX,1                ;Times 4
  88.     SAL    AX,1                ;Times 8
  89.     SAL    AX,1                ;Times 16
  90.     MOV    BX,AX                ;Goes into address
  91.     AND    BH,7                ; without adjustment
  92.     SAL    AX,1                ;Times 32
  93.     SAL    AX,1                ;Times 64
  94.     ADD    BX,AX                ;Addr gets Y-coord times 80
  95. ;
  96. ;Add X-coordinate to address
  97.     MOV    AX,SI                ;Get X-coordinate
  98.     SAR    AX,1                ;Divide
  99.     SAR    AX,1                ; by 4
  100.     ADD    BX,AX                ;Here is the address
  101. ;
  102. ;Compute the rotated mask and color
  103.     AND    SI,3                ;Just pixel position into index
  104.     SAL    SI,1                ;Index times 2
  105.     SAL    SI,1                ;Index times 4
  106.     ADD    SI,DX                ;4 * pixel position + color
  107.     SAL    SI,1                ;8 * pixel position + 2 * color
  108.     MOV    AX,CTABLE[SI]            ;Look up rotated color & mask
  109. ;
  110. ;Insert the color into the video byte
  111.     AND    AL,ES:[BX]            ;Get old byte & remove old pixel
  112.     OR    AL,AH                ;Insert new color
  113.     MOV    ES:[BX],AL            ;Put the byte back
  114. ;
  115.     POP    AX                ;Restore registers
  116.     POP    SI
  117.     POP    BX
  118.     RET
  119. SET_PT    ENDP
  120. ;------------------------------------------------------------------------------
  121. ;Routine to XOR a point onto medium resolution color screen 
  122. ;
  123. XOR_PT    PROC    FAR
  124.     PUSH    BX                ;Save registers
  125.     PUSH    SI
  126.     PUSH    AX
  127. ;
  128. ;Multiply Y-coord by bytes/row & adjust for even/odd lines
  129.     MOV    AX,DI                ;Get Y-coordinate into part
  130.     MOV    AH,AL                ; and  into high part
  131.     AND    AX,01FEH            ;Mask off unwanted parts
  132.     SAL    AX,1                ;Times 4
  133.     SAL    AX,1                ;Times 8
  134.     SAL    AX,1                ;Times 16
  135.     MOV    BX,AX                ;Goes into address
  136.     AND    BH,7                ; without adjustment
  137.     SAL    AX,1                ;Times 32
  138.     SAL    AX,1                ;Times 64
  139.     ADD    BX,AX                ;Addr gets Y-coord times 80
  140. ;
  141. ;Add X-coordinate to address
  142.     MOV    AX,SI                ;Get X-coordinate
  143.     SAR    AX,1                ;Divide
  144.     SAR    AX,1                ; by 4
  145.     ADD    BX,AX                ;Here is the address
  146. ;
  147. ;Compute the mask for color and use it
  148.     AND    SI,3                ;Just the bit count into index
  149.     SAL    SI,1                ;Index times 2
  150.     SAL    SI,1                ;Index times 4
  151.     ADD    SI,DX                ;4 * pixel position + color
  152.     SAL    SI,1                ;8 * pixel position + 2 * color
  153.     MOV    AX,CTABLE[SI]            ;Look up rotated color & mask
  154.     XOR    ES:[BX],AH            ;XOR the byte with the color
  155. ;
  156.     POP    AX                ;Restore registers
  157.     POP    SI
  158.     POP    BX
  159.     RET
  160. XOR_PT    ENDP
  161. ;------------------------------------------------------------------------------
  162. ;Routine to return color of a point on med res color screen 
  163. ;
  164. GET_COLOR    PROC    FAR
  165.     PUSH    BX                ;Save registers
  166.     PUSH    CX
  167. ;
  168. ;Multiply Y-coord by bytes/row & adjust for even/odd lines
  169.     MOV    AX,DI                ;Get Y-coordinate into part
  170.     MOV    AH,AL                ; and  into high part
  171.     AND    AX,01FEH            ;Mask off unwanted parts
  172.     SAL    AX,1                ;Times 4
  173.     SAL    AX,1                ;Times 8
  174.     SAL    AX,1                ;Times 16
  175.     MOV    BX,AX                ;Goes into address
  176.     AND    BH,7                ; without adjustment
  177.     SAL    AX,1                ;Times 32
  178.     SAL    AX,1                ;Times 64
  179.     ADD    BX,AX                ;Addr gets Y-coord times 80
  180. ;
  181. ;Add X-coordinate to address
  182.     MOV    AX,SI                ;Get X-coordinate
  183.     SAR    AX,1                ;Divide
  184.     SAR    AX,1                ; by 4
  185.     ADD    BX,AX                ;Here is the address
  186. ;
  187. ;Compute the position of the pixel in the byte
  188.     MOV    CX,SI                ;Use X-coord to determine count
  189.     AND    CX,3                ;Just the bit count
  190.     INC    CX                ; plus one
  191.     SAL    CX,1                ;2 bits/pixel
  192. ;
  193. ;Get the byte and rotate into place
  194.     MOV    AL,ES:[BX]            ;Get old byte
  195.     ROL     AL,CL                ;Rotate left this many times
  196.     AND    AX,3                ;Just the pixel color
  197. ;
  198.     POP    CX                ;Restore registers
  199.     POP    BX
  200.     RET
  201. GET_COLOR    ENDP
  202. ;------------------------------------------------------------------------------
  203. ;Routine to set & fill a rectangular box
  204. ;
  205. SET_BOX    PROC    FAR
  206.     PUSH    SI                ;Save registers
  207.     PUSH    DI
  208.     PUSH    DX
  209.     PUSH    BX
  210.     PUSH    CX
  211.     PUSH    AX
  212. ;
  213. ;Determine byte position for start
  214. ;
  215. ;Get Y contribution
  216.     MOV    AX,Y1                ;Get starting Y-coordinate
  217.     MOV    AH,AL                ;Replicate for odd/even bank
  218.     AND    AX,01FEH            ;Mask off unwanted parts
  219.     SAL    AX,1                ;Times 4
  220.     SAL    AX,1                ;Times 8
  221.     SAL    AX,1                ;Times 16
  222.     MOV    DI,AX                ;Addr gets Y-coord * 16
  223.     AND    DI,7FFH                ;Not the odd/even bit
  224.     SAL    AX,1                ;Times 32
  225.     SAL    AX,1                ;Times 64
  226.     ADD    DI,AX                ;Addr gets Y-coord * 80
  227. ;
  228. ;Add in X contribution
  229.     MOV    AX,X1                ;Get X-coordinate
  230.     SAR    AX,1                ;Divide
  231.     SAR    AX,1                ; by 4
  232.     ADD    DI,AX                ;Beginning of offset
  233. ;
  234. ;Count for outer loop
  235.     MOV    CX,Y2                ;Ending Y-coordinate
  236.     SUB    CX,Y1                ; minus starting Y-coordinate
  237.     INC    CX                ; plus one
  238. ;
  239. ;Count for inner loop
  240.     MOV    SI,X2                ;Ending X-coordinate
  241.     SAR    AX,1                ;Divide
  242.     SAR    AX,1                ; by 4
  243.     MOV    AX,X1                ;Starting X-coordinate
  244.     SAR    AX,1                ;Divide
  245.     SAR    AX,1                ; by 4
  246.     SUB    SI,AX                ;Take the difference
  247.  
  248. ;Get the color
  249.     MOV    BX,COLOR            ;Get the color
  250.     AND    BX,3                ;Just between 0 & 3
  251.     MOV    DL,CBYTES[BX]            ;Look up color pattern
  252. ;
  253. ;Determine mask for start & ending bytes
  254.     MOV    BX,X1                ;Starting byte
  255.     AND    BX,3                ;Just the pixel position
  256.     SAL    BX,1                ;Times 2
  257.     SAL    BX,1                ;Times 4
  258.     MOV    AX,X2                ;Ending byte
  259.     AND    AX,3                ;Just the pixel position
  260.     ADD    BX,AX                ;4 * starting + ending
  261.     SAL    BX,1                ;8 * starting + 2 * ending
  262.     MOV    BX,XTABLE[BX]            ;Look up the masks
  263. ;
  264. ;Set up masked color bytes
  265.     MOV    DH,DL                ;Color for left bytes
  266.     MOV    AH,DL                ;Color for middle bytes
  267.     AND    DX,BX                ;Mask left & right color bytes
  268. ;
  269.     CLD                    ;Forward
  270. SBOXLOOP:
  271.     PUSH    CX                ;Save count of outer loop
  272.     PUSH    DI                ;Save initial byte position
  273. ;
  274.     MOV    CX,SI